/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package modelo.tableModels.editors;

import vista.admin.Dialog_Objetivo_PlanGeneral;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.AbstractCellEditor;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;
import semillas_609_dev.Semillas_609_devApp;

/**
 *
 * @author Felipe
 */
public class Objetivo_TableCellEditor extends AbstractCellEditor implements TableCellEditor,ActionListener{

    String objetivo;
    JButton button;
    Dialog_Objetivo_PlanGeneral objetivoDialog;
    protected static final String EDIT = "edit";

    public Objetivo_TableCellEditor() {
        button = new JButton();
        button.setActionCommand(EDIT);
        button.addActionListener(this);
        button.setBorderPainted(false);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (EDIT.equals(e.getActionCommand())) {
            objetivoDialog = new Dialog_Objetivo_PlanGeneral(Semillas_609_devApp.getApplication().getMainFrame(), true, "Modificar Objetivo...",this.objetivo);
            objetivoDialog.setLocationRelativeTo(Semillas_609_devApp.getApplication().getMainFrame());
            Semillas_609_devApp.getApplication().show(objetivoDialog);
            this.objetivo = objetivoDialog.getObjetivo();
            fireEditingStopped(); //Make the renderer reappear.            
        } else { //User pressed dialog's "OK" button.
        }
    }

    //Implement the one CellEditor method that AbstractCellEditor doesn't.
    @Override
    public Object getCellEditorValue() {
        return objetivo;
    }

    //Implement the one method defined by TableCellEditor.
    @Override
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
        objetivo = (String)value;
        button.setText(objetivo);
        return button;
    }


   
}
